package product

import (
	"wx-uniapp-go/internal/domain/errcode"
	"wx-uniapp-go/internal/logic/product_logic"
	"wx-uniapp-go/internal/repository/dto"
	"wx-uniapp-go/internal/server/echo"

	"github.com/gin-gonic/gin"
)

// ListCategory 获取商品分类列表
func ListCategory(c *gin.Context) {
	ctx := echo.TraceCtx(c)

	req := new(dto.ListCategoryReq)
	if err := c.ShouldBindQuery(req); err != nil {
		echo.Fail(c).Error(errcode.ParametersErr)
		return
	}

	resp, err := product_logic.NewProductLogic(ctx).ListCategory(req)
	if err != nil {
		echo.Fail(c).Error(err)
		return
	}

	echo.Success(c, resp)
}
